package com.yyds.controller;

import com.yyds.common.MyJSON;
import com.yyds.common.R;
import com.yyds.service.PreventAreaService;
import com.yyds.vo.PreventAreaVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("admin/prevent/area")
public class PreventAreaContorller {

    @Autowired
    private PreventAreaService preventAreaService;


    //查全部封控地区
    @RequestMapping("/list")
    public MyJSON<PreventAreaVo> selectAllPreventAreaController(@RequestParam Map<String, Object> params) {
        // 注意 这里使用 map来接受参数  前端传的不定参数 都可以封装到 map 中
        System.out.println("public MyJSON<PreventAreaVo> selectAllPreventAreaController(@RequestParam Map<String, Object> params) =" + params);
        return preventAreaService.selectAllPreventAreaService(params);
    }

    //查全部名字
    @RequestMapping("/selectAreaName")
    public R selectAreaNameController() {
        List<String> list = preventAreaService.selectAreaNameService();
        return R.ok().data("residentName", list);
    }

    //添加封控地区
    @RequestMapping("/add")
    public R add(PreventAreaVo preventAreaVo) {
        int result = preventAreaService.insertPreventAreaService(preventAreaVo);
        return result > 0 ? R.ok() : R.error();
    }

    //删除封控区域
    @RequestMapping("/delete")
    public R delete(Integer area_id) {
        int result = preventAreaService.deletePreventAreaServiceById(area_id);
        System.out.println(area_id);

        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    //    部分删除
    @RequestMapping("/deleteAll")
    public R deleteAllPreventArea(String str) {
        System.out.println("deleteAllPreventArea str" + str);
        Integer i = preventAreaService.deleteAllPreventArea(str);
        return i > 0 ? R.ok() : R.error();
    }

    //修改
    @RequestMapping("/update")
    public R updatePreventAreaServiceById(PreventAreaVo preventAreaVo) {
        System.out.println("public R updatePersonVolunteerController(PreventAreaVo preventAreaVo) = " + preventAreaVo);

        int result = preventAreaService.updatePreventAreaService(preventAreaVo);
        return result > 0 ? R.ok() : R.error();

    }

    //统计
    @RequestMapping("/count")
    public R selectCountPreventArea() {

        int num = preventAreaService.selectCountPreventArea();

        return R.ok().data("value" ,num);
    }

}
